package main

import (
	_ "go_backend/models"
	_ "go_backend/routers"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {

	//数据库配置
	dbuser := beego.AppConfig.String("dbuser")
	dbpassword := beego.AppConfig.String("dbpwd")
	dbname := beego.AppConfig.String("dbname")
	dbcharset := beego.AppConfig.String("dbcharset")
	dbaddr := beego.AppConfig.String("dbaddr")

	orm.Debug = true //开启debug
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", dbuser+":"+dbpassword+"@tcp("+dbaddr+")/"+dbname+"?charset="+dbcharset)
	//models.RegisterModel() //注册model
	o := orm.NewOrm()
	//默认使用数据库default
	o.Using("default")

}
func main() {
	// 查询所有
	//users := models.QueryUserAll()
	//fmt.Println(users)
	// 查询(id)
	//user, _ := models.QueryUserById(8)
	//fmt.Println(user.Id, user.Nickname, user.Sex)
	//o:=orm.NewOrm()
	//user:=new(models.YyStatUser)
	//user.Date=time.Now()
	//fmt.Println(o.Insert(user))

	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.Run()
}
